#include "TrChartMainArea.h"
#include <QDebug>
#include <QPainter>
#include <QHBoxLayout>

TrChartMainArea::TrChartMainArea(QWidget *parent) : QWidget(parent)
{

    setLayout(new QVBoxLayout);

    m_pChartAxis = new TrChartAxisX;
    m_pMainSplitter = new QSplitter(Qt::Vertical);
    layout()->addWidget(m_pMainSplitter);
    layout()->addWidget(m_pChartAxis);
    layout()->setMargin(0);

    m_pChartKline = new TrChartKline;

    m_pMainSplitter->insertWidget(0, m_pChartKline);
    m_pMainSplitter->insertWidget(1, new TrChartSubIndicator);
    m_pMainSplitter->insertWidget(2, new TrChartSubIndicator);
    m_pMainSplitter->setStretchFactor(0, 6);
    m_pMainSplitter->setStretchFactor(1, 2);
    m_pMainSplitter->setStretchFactor(2, 2);

    m_pMainSplitter->setStyleSheet("QSplitter::handle {border-bottom: 1px solid #222631;height: 1px;}");

}

void TrChartMainArea::paintEvent(QPaintEvent* event)
{
    Q_UNUSED(event)
    this->setAutoFillBackground(true);
    QPalette palette;
    palette.setColor(QPalette::Window, TrColor_BackGround);
    this->setPalette(palette);

    QPainter painter(this);
    QPen     pen;
    pen.setColor(TrColor_BackGrid);
    pen.setWidth(1);
    painter.setPen(pen);

    painter.drawLine(width()-g_iAxisYVlineWidth, 0, width()-g_iAxisYVlineWidth, height());

}

void TrChartMainArea::mouseMoveEvent(QMouseEvent* event)
{
    m_pMousePoint = event->pos();
    qDebug() << m_pMousePoint.x() << m_pMousePoint.y();
    drawMouseCross();
}

void TrChartMainArea::mousePressEvent(QMouseEvent* event)
{
    Q_UNUSED(event)
}

void TrChartMainArea::resizeEvent(QResizeEvent* event)
{
    Q_UNUSED(event)
}

void TrChartMainArea::mouseDoubleClickEvent(QMouseEvent *event)
{
    Q_UNUSED(event)
    m_bShowMouseCross = m_bShowMouseCross == false ? true : false;
}

void TrChartMainArea::drawMouseCross()
{

}


